<?php

// A bug in PHP < 5.2.2 makes $HTTP_RAW_POST_DATA not set by default, 
// but we can do it ourself.
if ( !isset( $HTTP_RAW_POST_DATA ) ) {
	$HTTP_RAW_POST_DATA = file_get_contents( 'php://input' );
}

/* fix for mozBlog and other cases where '<?xml' isn't on the very first line */
if ( isset($HTTP_RAW_POST_DATA) )
	$HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);

$xmlrpc_request = XMLRPC_parse($HTTP_RAW_POST_DATA);
$method_name = XMLRPC_getMethodName($xmlrpc_request);
$params = XMLRPC_getParams($xmlrpc_request);

$forum_methods['pagina.editar'] = "pagina_editar";
$forum_methods['pagina.contacto'] = "pagina_contacto";
$forum_methods['method_not_found'] = "XMLRPC_method_not_found";

if (!isset($forum_methods[$method_name])) {
	$forum_methods['method_not_found']($method_name);
} else {
	$forum_methods[$method_name]($params);
}

function pagina_editar($params) {
	
	// Check if params are right
	if (count($params) != 4) {
		XMLRPC_error("100", "Wrong parameter count");
		return 0;
	}
	$titulo = $params[0];
	$contenido = $params[1];
	$slug = $params[2];
	$id = $params[3];
	
	
	$article = new Article();
	if ($id) {
		$article->load($id);
	}
	$article->title = $titulo;
	$article->content = $contenido;
	$article->slug = $slug;
	
	print_r($article);
	
	$article->save();
}

function pagina_contacto($params) {
	
	// Check if params are right
	if (count($params) != 4) {
		XMLRPC_error("100", "Wrong parameter count");
		return 0;
	}
	list($nombre, $mail, $asunto, $mensaje) = $params;

        mail("contacto@sumacero.com.ar", "De ".$nombre.": ".$asunto, $mensaje, "From: $nombre <$mail>");

        print_r("Gracias por contactarse con nosotros");

}


exit;
print_r($xmlrpc_request);
print_r($methodName);
print_r($params);


?>